开发者

My app keeps me redirecting to Account/LogOn?ReturnUrl=%2f

I created an MCV 3 app and deployed it to a development server in my organization. It works OK in my development machine. However, I noticed that in the dev server, the application redirects me to Account/LogOn?ReturnUrl=%2f web page even after I've logged in correctly. I also see that sometimes some of the assets(CSS, Javascript, images) are not served either.

The error message shown is below. After refreshing the page, the application works just fine. If I don't accesss the app in a little while, the error comes back.开发者_如何学运维 Any ideas?

Server Error in '/' Application.

The resource cannot be found.

Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.

Requested URL: /Account/LogOn


This is fairly common. For resources style sheets, etc, it's usually a result of not using @Content.Url. My guess is that for the other issues, you might be hardcoding your links instead of using @Url.Action. Again this is common, I have ran into it a bunch of times.

Really basically in development environment you're not really concerned with virtual directories-- however in production environment it's more of an issue.

I would think that /Account/Login points to root directory when using IIS IIS, you want to point to to this route via the virtual directory. If the link is generated through something like <%=Html.ActionLink %>, then you're fine. But if you have some javascript and you're calling a URL, or if your hardcoding your links to /MyController/MyList then it won't find it.

Same with css files. If you look at how the Site.css file is accessed when creating a new project, then you'll see something like this:

<link href='<%=Url.Content("~/Content.Site.css")%>' etc.. etc..

Let me know if this makes sense.


The solution was to disable forms authentication in IIS.


You may be seeing this because your web.config file has the wrong allow role="RoleNameHere"

If you set up your webconfig page for Roles like this below make sure the role matches what you set the login role as. For instance, you may have written Administrators instead of the correct Administrator. Once you write the role correctly, the ReturnUrl goes away and you can access the page again after logging in.

<location path="AdminDepartments.aspx">
    <system.web>
      <authorization>
        <allow roles="Administrator"/>
        <deny users="*"/>
      </authorization>
    </system.web>
</location>


Like ek_ny said, this is very common issue. You should create these two variables on a global scale for your application.

On the code behind side, put this in a class that can be accessed by all the pages:

Public String SiteRootPath = (New Control).ResolveUrl("~/");

On the front end, put in the master page file:

var jvSiteRootPath="<%=SiteRootPath %>";

Now you can use that for all urls that need to be referenced from the root path.


I think you should enable Anonymous Authentication of your website along with Forms Authentication.

Select your application on IIS then in feature view choose authentication .

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜