开发者

Asp.Net forms authentication redirects to .../myapp/default.aspx instead of .../myapp/

开发者 https://www.devze.com 2023-01-12 15:32 出处:网络
After authentication, asp.net redirects my users to .../myapp/default.aspx instead of .../myapp/ Is there some way of fixing thi开发者_开发问答s? I think it\'s a little ugly not to mention redundant

After authentication, asp.net redirects my users to .../myapp/default.aspx instead of .../myapp/

Is there some way of fixing thi开发者_开发问答s? I think it's a little ugly not to mention redundant to contain the extra default.aspx on the url.

I've tried putting the following code in my default.aspx.cs page_load function, but it results in a redirect loop because it cannot distinguish whether the user is accessing myapp/ or myapp/default.aspx:

if (Request.RawUrl.ToLower().EndsWith("/default.aspx"))
  Response.Redirect("./");

Thanks!


If you are using a login control, decide yourself how the redirect will happen. Use the login control's event (I think it is Authenticate) and:

if (Request.QueryString["ReturnUrl"] != null)  
{  
    FormsAuthentication.RedirectFromLoginPage("someuserid", false);  
}  
else  
{  
    FormsAuthentication.SetAuthCookie("someuserid", false);  
    Response.Redirect("~/SomePage.aspx");  
} 


The easiest way to fix this is just to remove the defaultUrl attribute from the web.config

<authentication mode="Forms">
    <forms ... defaultUrl="default.aspx" ... />
</authentication>

When you visit www.yourwebsite.com/myapp, the return url will be "/myapp/", and after login, it will redirect back to "/myapp/". If you use the defaultUrl like above, it will redirect to "/myapp/default.aspx". Actually, I experimented with this on the root of the site, but I would think it works the same for subdirectories.


You will need to look at the default page that is set up in IIS.


It's not a redundant redirect.

Why? Because when you hit / on a web server, the webserver redirects you to /default.aspx anyway. You're just letting IIS do it instead of the authentication mechanism.

-Oisin


Actually there is no such file like "./" to process for a web server. There MUST be a default file which will be served to client. Because nobody wants to type "blabla.com/index.aspx" instead of "blabla.com". Your problem is choosing which page to be called as default.

In IIS, right-click to your web site and go for properties.

There is a tab, which contains "Default Page" order. There must be a couple of web pages like "index.htm, default.aspx, etc". Change these filenames' order. The page you want to be called must be at the top.

PS: YOUR Login page and Logged page are same page! So it will be called redundantly!


I was having the same issue. My login page was default.aspx and when you hit the application, the redirect url was set to /MyApp/.

I think the end result is that I had to rename my login page to soemthing else (login.aspx)

0

精彩评论

暂无评论...
验证码 换一张
取 消