开发者

How do I display a message in an Asp.NET Forms Authentication redirect?

I have a web app using forms authentication and I have restricted开发者_如何学Go a folder so that only those with an administrator role can access it. I am controlling all of this through the web.config file and adding the proper location tags to restrict access.

Currently the application is working fine. If I am logged in as a user and click the link to the administration section, I'm redirected to the login page once again. If I look at the URL, the ReturnUrl parameter is set properly.

What I'd like to do is to display a message to the user indicating insufficient security privileges, or something to that effect so the user doesn't think they are getting logged out of the application prematurely or that the application isn't working.

Does anybody know of a way to do this?


You can redirect to a page that displays an alert box, and which then (on the client) redirects to the page you want to be at.


I gave no sample code because I don't have time now to get it right. Here's the wrong code:

if (FormsAuthentication.Authenticate(userName, passWord))
{
    Response.Redirect("alertPage.html?ReturnUrl=" + Request.QueryString["ReturnUrl"]);
}

on alertPage.html:

<script language="javascript">
    alert('Some message');
    window.navigator.location = // get the URL and use it
</script>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜