使用 ASP.Net 2.0,您可以使用该Title属性来更改页面标题:
Page.Title = "New Title";
Run Code Online (Sandbox Code Playgroud)
但由于在 ASP.Net 1.1 中,类中没有属性Title,Page因此如何从代码隐藏中更改页面的标题?
当显示模式弹出窗口时,我需要以编程方式调用以下内容来设置某些内容。
Sys.Application.add_load(modalSetup);
Run Code Online (Sandbox Code Playgroud)
一些顺理成章的事情。
<script type='text/javascript'>
Sys.Application.add_load(modalSetup);
function modalSetup() {
var modalPopup = $find("PopupBehaviorId");
if (modalPopup != null) {
modalPopup.add_shown(SetFocusOnControl);
}
}
function SetFocusOnControl() {
alert('test');
}
</script>
Run Code Online (Sandbox Code Playgroud)
现在的问题是我script manager在主页上有一个。
如果我手动(不是以编程方式)将此脚本放在 的下面script manager in the master page,它将正常工作。
但是,当我使用任一方法以编程方式将其添加到模式弹出窗口(我需要)的用户控件中时ScriptManager.RegisterClientScriptBlock or Page.ClientScript.RegisterClientScriptBlock,它会引发著名的sys is undefined错误。
我知道这种情况正在发生,因为这个程序注入将其放入该行执行Head section之前。ScriptManager
我该如何解决这个问题。是否可以说将此脚本插入到页面末尾而不是顶部?
我正在开发一个网站,该网站允许用户上传不同的文件格式。我们需要限制用户上传受密码保护的文件。
有没有办法在上传文件之前确定 Microsoft Office 文件(Word、Powerpoint 和 Excel)是否受密码保护?根据http://social.msdn.microsoft.com/Forums/en/oxmlsdk/thread/34701a34-f1d4-4802-9ce4-133f15039c69,我已经实现了以下内容,但它抛出一个错误,提示“文件包含损坏的数据” ,同时尝试打开受密码保护的文件。
using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(mem, false))
{
DocumentProtection dp =
wordDoc.MainDocumentPart.DocumentSettingsPart.Settings.GetFirstChild<DocumentProtection>();
if (dp != null && dp.Enforcement == DocumentFormat.OpenXml.OnOffValue.FromBoolean(true))
{
return true;
}
}
Run Code Online (Sandbox Code Playgroud)
还有其他方法可以确定这一点吗?
我正在开发 ASP.net Web Form,我想在网站中实现 AutoFac。
我已按照以下链接中的步骤操作: https ://autofaccn.readthedocs.io/en/latest/integration/webforms.html
但我收到了这个错误:
该模块要求 HttpApplication(全局应用程序类)实现 IContainerProviderAccessor。
Global.asax.cs我在我的项目中找不到,只有Global.asax.
Global.asax:
<%@ Application Language="C#" %>
<%@ Import Namespace="Autofac" %>
<%@ Import Namespace="Autofac.Integration.Web" %>
<script RunAt="server">
public class Global : HttpApplication, IContainerProviderAccessor {
// Provider that holds the application container.
static IContainerProvider _containerProvider;
// Instance property that will be used by Autofac HttpModules
// to resolve and inject dependencies.
public IContainerProvider ContainerProvider {
get { return _containerProvider; }
}
void Application_Start(object sender, EventArgs e) …Run Code Online (Sandbox Code Playgroud) 我有一个带有一些 ASP.NET 控件的 Web 表单,我想使用它们的 ID 选择每个控件。当我启动页面时,所有名称都会更改。
有没有一个简单的方法来使用这个。我不想使用类作为选择器。
我需要使用表单身份验证将 Facebook(以及后来的 google 等)身份验证添加到现有的 asp.net webforms 应用程序。
我快到了,但表单身份验证和 owin 身份验证之间似乎存在冲突。我的解决方案基于标准的 VS 2015 模板。
重定向到外部身份验证提供程序(facebook)的相关代码如下:
string redirectUrl =
ResolveUrl(String.Format(CultureInfo.InvariantCulture,
"~/Account/RegisterExternalLogin?{0}={1}&returnUrl={2}", IdentityHelper.ProviderNameKey,
provider, ReturnUrl));
var properties = new AuthenticationProperties { RedirectUri = redirectUrl };
Context.GetOwinContext().Authentication.Challenge(properties, provider);
Response.StatusCode = 401;
Response.End();
Run Code Online (Sandbox Code Playgroud)
如果我关闭表单身份验证,这会起作用。如果我有表单身份验证,用户将被重定向到 web.config 中定义的表单身份验证 URL:
<authentication mode="Forms">
<forms name=".ASPXAUTH_Test" loginUrl="~/start/login.aspx" timeout="60" >
</forms>
</authentication>
Run Code Online (Sandbox Code Playgroud)
根据我的理解,Http 状态代码 (401) 会触发重定向到 web.config 中的 Url。我试图设置其他状态代码,但它们根本不起作用。当我在 web.config 中关闭表单身份验证时,实际的登录过程仍然有效(令人惊讶)但是如果我在未登录的情况下访问受保护的页面,则会得到一个丑陋的 IIS 错误页面,而不是被重定向。
看来,我无法获得工作表单身份验证和外部身份验证才能正常工作:-(
到目前为止,所有替代方案对我来说似乎都不诱人: - 切换到身份框架(在我们的特定环境中,这绝对不是一个选项。我只是为了完整性才提到它) - 尝试使用 web.api 或其他东西类似(可能有同样的问题) - 放弃 owin 外部身份验证并手动实现所有内容
有没有人能够完成这项工作?任何帮助表示赞赏。提前致谢。
大家好,我知道如何快速简单地在我的 ASP.NET MVC 项目中构建 Log4Net [参考],但是如何在纯“Web Form”项目中做到这一点,请帮助我解决这个问题,一步一步谢谢。
顺便说一句,我也一直在寻找一些解决方案来解决我的问题,但这对我来说不是好方法,就像 Stackoverflow 上的以下问题
1. 使用 log4net 与 asp.net web 表单
2. 无法编写在 ASP.NET Web 窗体站点中使用 log4net 将日志记录到文件
PS:我也会尝试解决这个问题,希望你或我能找到一些好主意来解决这个问题。
我想说它只是从我的阅读和理解来看是服务器端的,但我希望得到一些澄清。谢谢。
namespace login_page
{
public partial class itemselect : Form
{
public itemselect()
{
InitializeComponent();
}
private void product_Click(object sender, EventArgs e)
{
}
private void Addproduct_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=DESKTOP-QI8RJIB;Initial Catalog=itemselect;Integrated Security=True");
con.Open();
SqlCommand cmd = new SqlCommand(" insert into itemselect([Product ID],[Product Name],[Product Quantity],[Product Price] values ('" +pid.Text+ "','" +pn.Text+ "','" +pq.Text+ "','" +pp.Text+ "')", con);
cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
this.Close();
MessageBox.Show("item added successfully");
}
Run Code Online (Sandbox Code Playgroud)
例外:
System.Data.SqlClient.SqlException: '关键字'values' 附近的语法不正确。'
webforms ×10
asp.net ×7
c# ×4
.net ×1
ado.net ×1
asp.net-1.1 ×1
asp.net-ajax ×1
autofac ×1
c#-4.0 ×1
client-side ×1
code-behind ×1
javascript ×1
jquery ×1
log4net ×1
nuget ×1
owin ×1
page-title ×1
server-side ×1
sql-server ×1