我需要检查我们的访问者是否使用HTTPS.在BasePage中,我检查请求是否来自HTTPS.如果不是,我会使用HTTPS重定向.但是,当有人来到该网站并使用此功能时,我收到错误:
System.Web.HttpException:在发送HTTP标头后,服务器无法附加标头.在Premier.Payment.Website.Generic.BasePage..ctor()的System.Web.HttpResponse.AddHeader(String name,String value)的System.Web.HttpResponse.AppendHeader(String name,String value)处
这是我开始使用的代码:
// If page not currently SSL
if (HttpContext.Current.Request.ServerVariables["HTTPS"].Equals("off"))
{
// If SSL is required
if (GetConfigSetting("SSLRequired").ToUpper().Equals("TRUE"))
{
string redi = "https://" +
HttpContext.Current.Request.ServerVariables["SERVER_NAME"].ToString() +
HttpContext.Current.Request.ServerVariables["SCRIPT_NAME"].ToString() +
"?" + HttpContext.Current.Request.ServerVariables["QUERY_STRING"].ToString();
HttpContext.Current.Response.Redirect(redi.ToString());
}
}
Run Code Online (Sandbox Code Playgroud)
我也尝试在上面添加它(我在另一个站点中使用了一点类似的问题):
// Wait until page is copletely loaded before sending anything since we re-build
HttpContext.Current.Response.BufferOutput = true;
Run Code Online (Sandbox Code Playgroud)
我在IIS 6上使用.NET 3.5中的c#.
如何在ASP.NET MVC3中使用HtmlHelper在窗体标记内嵌套多个标签和输入?
我的代码如下:
public static string GenerateFormForContact(this HtmlHelper helper, string method, string action, bool includeMailTag)
{
//form tag
TagBuilder form = new TagBuilder("form");
form.Attributes.Add("action", action);
form.Attributes.Add("method", method);
//label and input tag
TagBuilder labelClientName = new TagBuilder("label");
labelClientName.Attributes.Add("for", "clientName");
TagBuilder inputClientName = new TagBuilder("input");
inputClientName.Attributes.Add("name", "clientName");
inputClientName.Attributes.Add("type", "text");
inputClientName.Attributes.Add("placeholder", "Your name");
inputClientName.Attributes.Add("required", "required");
//how to insert inside form
TagBuilder labelEmailName = new TagBuilder("label");
labelEmailName.Attributes.Add("for", "emailName");
TagBuilder inputEmailName = new TagBuilder("input");
inputEmailName.Attributes.Add("name", "emailName");
inputEmailName.Attributes.Add("type", "email");
inputEmailName.Attributes.Add("placeholder", "Your mail");
inputEmailName.Attributes.Add("required", "required");
//how to …Run Code Online (Sandbox Code Playgroud) 我有这个简单的SQL语句:
select Expr1.value - Expr2.value FROM
(SELECT
Expr1 = (SELECT COUNT(ID) FROM Table1),
Expr2 = (SELECT COUNT(ID_) FROM Table1 WHERE (UPDATED > CREATED))
)
Run Code Online (Sandbox Code Playgroud)
它抛出了我的错误:
无法绑定多部分标识符'Expr1.value'无法绑定多部分标识符'Expr2.value'
我的错误在哪里?
我在Stackoverflow中读过,但很多主题仅涉及INNER JOIN语句.我正在寻找Expr1和之间的区别Expr2.(并显示结果)
我有以下字典内容:
[0] {75, SimpleObject}
[1] {56, SimpleObject}
[2] {65, SimpleObject}
[3] {12, SimpleObject}
...
Run Code Online (Sandbox Code Playgroud)
我希望得到第一把钥匙,意味着75,没有foreach.
也许这个key词应该引用[0]而不是75.
因为基于该键,我想使用它SimpleObject,我写道:
SimpleObject s = dictionary[0] as SimpleObject;
Run Code Online (Sandbox Code Playgroud)
但是VS2010引发了一个异常:
The given key was not present in the dictionary.
Run Code Online (Sandbox Code Playgroud)
我知道这[0]意味着字典中的键号0,意味着我可以拥有
[0] {72, SimpleObject} //here
[1] {56, SimpleObject}
[2] {65, SimpleObject}
[3] {12, SimpleObject}
...
Run Code Online (Sandbox Code Playgroud)
那我应该找通讯员SimpleObject.
对不起,是第一次使用词典,我想了解更多.
问题:如何获取数字75和他的SimpleObject?
谢谢.
PS:我知道在StackOverflow中已经存在类似的主题,但它们中没有一个能帮助我获得该密钥.
我写了这个简单的javascript代码:
$("input[type='file']").attr("value", "");
Run Code Online (Sandbox Code Playgroud)
它适用于Firefox和Chrome,但不适用于IE(我在IE9中试过)
清空输入类型文件值的好方法是什么?
谢谢
我使用现有的AccountController(由MVC制作)测试登录方法时遇到问题...
我有这个简单的测试方法:
[TestMethod]
public void LogOnTest1() {
AccountController controller = new AccountController();
LogOnModel logonModel = new LogOnModel();
logonModel.UserName = "test";
logonModel.Password = "test1234";
if ( controller.MembershipService == null ) {
controller.MembershipService = new AccountMembershipService();
}
if ( controller.FormsService == null ) {
controller.FormsService = new FormsAuthenticationService();
}
var result = controller.LogOn( logonModel, "" ) as ViewResult;
Assert.AreEqual( "Index", result.ViewName );
}
Run Code Online (Sandbox Code Playgroud)
和定义的方法AccountController:
[HttpPost]
public ActionResult LogOn( LogOnModel model, string returnUrl ) {
if ( ModelState.IsValid ) {
if …Run Code Online (Sandbox Code Playgroud) 我有一个专用于下载文件的控制器,看起来像:
public ActionResult Download( string ids )
{
MyFileModel myfile = new MyFileModel(ids);
Stream s = myfile.GetStream();
return File( s, contentType, newFileName );
}
Run Code Online (Sandbox Code Playgroud)
我看到File从返回是FileStreamResult但我的内存已满(我有8GB并下载7GB的raeches)和CPU 100%
如何优化下载?
我有一个组件,其 html 结构如下所示:
<img mat-card-sm-image src="{{img}}" />
Run Code Online (Sandbox Code Playgroud)
并在打字稿中
constructor(private loginService: LoginService) {
this.img = null;
this.loadImage();
}
loadImage = function () {
this.img = this.loginService.loginImg();
}
Run Code Online (Sandbox Code Playgroud)
和登录服务:
loginImg() {
const url = "http://localhost:59078/api/image/login";
this.http.get(url, { responseType: 'blob' }).subscribe(result => {
console.log(result);
return result;
});
}
Run Code Online (Sandbox Code Playgroud)
和 API 核心控制器
[HttpGet]
[AllowAnonymous]
[Produces("image/png")]
public IActionResult Login()
{
var file = Path.Combine(Directory.GetCurrentDirectory(),
"wwwroot", "images", "login.png");
return PhysicalFile(file, "image/png");
}
Run Code Online (Sandbox Code Playgroud)
图像未加载的想法......为什么?
我有以下 C# 代码行,其中打开进程并运行 dotnet 命令来打开我的控制台应用程序(使用 .net 标准/核心创建)
var args = new Dictionary<string, string> {
{ "-p", "title"},
{ "-l", "games"},
...
};
var arguments = string.Join(" ", args.Select((k) => string.Format("{0} {1}", k.Key, "\"" + k.Value + "\"")));
var dllPath = @"C:\Users\xyz\Documents\Visual Studio 2017\myConsole\bin\Debug\netcoreapp2.1\myConsole.dll";
ProcessStartInfo procStartInfo = new ProcessStartInfo();
procStartInfo.FileName = "C:\....\cmd.exe";
procStartInfo.Arguments = $"dotnet \"{dllPath}\" {arguments}";
procStartInfo.UseShellExecute = false;
procStartInfo.CreateNoWindow = false;
procStartInfo.RedirectStandardOutput = true;
procStartInfo.RedirectStandardError = true;
StringBuilder sb = new StringBuilder();
Process pr = new Process();
pr.StartInfo = …Run Code Online (Sandbox Code Playgroud) 我有一个看起来像的字符串:
var a = @"DISC?INFO:
blablabla";
Run Code Online (Sandbox Code Playgroud)
我想检测DISC INFO该字符串中是否存在。
我做的很简单:
var index = a.IndexOf("disc info", StringComparison.OrdinalIgnoreCase);
Run Code Online (Sandbox Code Playgroud)
它返回我-1...
为什么呢 我希望找到它
整个C#代码:https://dotnetfiddle.net/DAgxau
c# ×7
asp.net ×2
.net-core ×1
angular ×1
dictionary ×1
header ×1
http ×1
https ×1
javascript ×1
jquery ×1
sql ×1
sql-server ×1
unit-testing ×1