基于用户重定向到母版页 [英] Based on user redirect to master page

查看:107
本文介绍了基于用户重定向到母版页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基于用户重定向到母版页无法使用





我的代码登录页面代码如下







protected void btnsubmit_Click(object sender,EventArgs e)

{



if(txtuser.Text ==admin)

{

Response.Redirect(〜/ MasterPage4.master );

}

if(txtuser.Text ==Employee)

{

Response.Redirect (〜/ MasterPage2.master);

}



}



如果管理员登录重定向到masterpage4.master和

如果员工登录重定向到masterpage2.master。



当我运行上面的代码时显示错误如下





此类页面不提供。



我的上述代码中的错误是什么。



我尝试了什么:



基于用户重定向到母版页无法使用





我的代码登录页码为关闭







protected void btnsubmit_Click(object sender,EventArgs e)

{



if(txtuser.Text ==admin)

{

Response.Redirect( 〜/ MasterPage4.master);

}

if(txtuser.Text ==Employee)

{

Response.Redirect(〜/ MasterPage2.master);

}



}



如果管理员登录重定向到masterpage4.master并且

如果员工登录重定向到masterpage2.master。



当我运行上面的代码时显示如下错误





此类页面不提供。



上面代码中的错误是什么。

解决方案

检查这个

以编程方式指定母版页(C#)| Microsoft Docs [ ^ ]

以编程方式使用ASP.NET母版页 [ ^ ]

c# - 如何动态设置母版页? - Stack Overflow [ ^ ]



将两个字符串与类似情况进行比较总是比较安全,请参阅 c# - 如何进行不区分大小写的字符串比较? - 堆栈溢出 [ ^ ]


您无法重定向到母版页。主页面只是一个包含在aspx页面的东西,所以它是一个aspx页面,你必须重定向到该页面将使用你的母版页。



如果你想根据不同的情况拥有不同的母版页,那么你可以通过编程方式指定母版页,但这通常是一个坏主意,有更好的方法来实现同样的目的。


Based on user redirect to master page is not working


My code login page code as follows



protected void btnsubmit_Click(object sender, EventArgs e)
{

if (txtuser.Text == "admin")
{
Response.Redirect("~/MasterPage4.master");
}
if (txtuser.Text == "Employee")
{
Response.Redirect("~/MasterPage2.master");
}

}

If admin login redirect to masterpage4.master and
if employee login redirect to masterpage2.master.

When i run the above code shows error as follows


This type of page is not served.

what is the mistake in my above code.

What I have tried:

Based on user redirect to master page is not working


My code login page code as follows



protected void btnsubmit_Click(object sender, EventArgs e)
{

if (txtuser.Text == "admin")
{
Response.Redirect("~/MasterPage4.master");
}
if (txtuser.Text == "Employee")
{
Response.Redirect("~/MasterPage2.master");
}

}

If admin login redirect to masterpage4.master and
if employee login redirect to masterpage2.master.

When i run the above code shows error as follows


This type of page is not served.

what is the mistake in my above code.

解决方案

check this
Specifying the Master Page Programmatically (C#) | Microsoft Docs[^]
Working with ASP.NET Master Pages Programmatically[^]
c# - How to Set Master Page dynamically? - Stack Overflow[^]

It is always safer to compare two string with similar case, refer this c# - How can I do a case insensitive string comparison? - Stack Overflow[^]


You can't redirect to a master page. The master page is simply something that is wrapped around an aspx page, so it is an aspx page you have to redirect to and that page will use your master page.

If you want to have different master pages based on different circumstances then you can specify the master page programmatically but this is generally a bad idea, there are better ways to achieve the same thing.


这篇关于基于用户重定向到母版页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆