标签: webmatrix

常规按钮元素提交表单,这怎么可能?

可能重复:
Javascript 添加删除行发送表单而不是添加行

我有一个包含两种形式的页面。

一种形式只有一个隐藏的输入元素,用于帮助连接查询字符串。

在另一个表单中,我有一个简单的按钮元素(不是输入类型提交按钮),想法是提交另一个表单 onclick(使用 JavaScript)。按钮就是这种形式。

就目前而言(出于测试目的),我目前所做的只是调用一个名为 changeSpec() 的 JavaScript 函数,其中绝对唯一的一行代码是一个警告框,它显示了隐藏输入元素的值。

按钮:

<td class="entry" colspan="3"><button onclick="changeSpec()">Change Species</button></td>
Run Code Online (Sandbox Code Playgroud)

带有隐藏输入元素的表单:

<form id="specChange" action="" method="get"><input id="hiddenSpec" type="hidden" value='@oppSpec' /></form>
Run Code Online (Sandbox Code Playgroud)

JavaScript 函数:

function changeSpec() 
{
    alert($("#hiddenSpec").val());
}
Run Code Online (Sandbox Code Playgroud)

当我单击普通按钮元素时,出现服务器端错误 (YSOD)...我的意思是,哇,没看到,哈哈。

我得到的错误与此无关,因为它是查询字符串中的一些强制转换错误,我仍然需要解决(此时,只要提交大表单 [不是上面显示的那个],就会发生这种 YSOD)。另外这个 YSOD 是运行时错误,而不是编译器错误,因为页面加载没有问题,直到它认为它已提交,并且随后执行 IsPost 分支。

无论如何,我可以以某种方式告诉(即使我设置 onclick=""),这个位于大表单中的按钮实际上是在尝试提交表单?

我之前不仅在其他表单中使用过常规按钮元素,而且一直认为常规按钮永远不会提交表单,我还多次清除缓存,只是为了确保没有任何愚蠢的(在那个级别)发生. 无论如何,似乎我需要接受有关 html 表单如何解释普通按钮元素的教育。

请帮忙,我在这里真的很茫然。这怎么可能?

谢谢,如果需要更多代码,请告诉我。

html javascript c# forms webmatrix

2
推荐指数
1
解决办法
1307
查看次数

Web.config 转换添加树

我想在发布时将以下内容添加到 web 配置中:

<system.webServer>
    <httpProtocol>
        <customHeaders>
            <add name="Strict-Transport-Security" value="max-age=16070400; includeSubDomains" xdt:Transform="Insert" />
        </customHeaders>
    </httpProtocol>
</system.webServer>
Run Code Online (Sandbox Code Playgroud)

默认 Web 配置中没有任何自定义标头,因此在发布时出现错误: No element in the source document matches '/configuration/system.webServer/httpProtocol/customHeaders'.

我可以修复它,只需将空元素添加到 web.config 中,如下所示:

  <httpProtocol>
    <customHeaders>
    </customHeaders>
  </httpProtocol>
Run Code Online (Sandbox Code Playgroud)

但是,感觉这不是正确的方法。

有没有更正确的方法在变换上构建元素树?

.net asp.net-mvc web-config webmatrix web.config-transform

2
推荐指数
1
解决办法
1588
查看次数

如何访问匿名类型?

List<Object> testimonials = new List<Object>();
testimonials.Add(new {
    Author = "Author 1",
    Testimonial = "Testimonial 1"
});
testimonials.Add(new {
    Author = "Author 2",
    Testimonial = "Testimonial 2"
});
testimonials.Add(new {
    Author = "Author 3",
    Testimonial = "Testimonial 3"
});

@ObjectInfo.Print(testimonials[DateTime.Now.DayOfYear % testimonials.Count].Author)
Run Code Online (Sandbox Code Playgroud)

给我一个错误CS1061:'object'不包含'Author'的定义

如何从推荐书列表中仅获得作者或推荐书?

c# anonymous-types webmatrix

1
推荐指数
1
解决办法
343
查看次数

通过WebMatrix将Javascript添加到DotNetNuke

我正在通过WebMatrix开发一个DotNetNuke网站,但无法弄清楚如何将javascript添加到主页.

我想在其中放置一个jQuery模块,确实显示了一个图库,但找不到添加脚本文件和编辑页面实际html的方法.

有没有人这样做过?

jquery dotnetnuke webmatrix

1
推荐指数
1
解决办法
821
查看次数

WebMatrix的深度报道?

大家好,我很好奇是否有任何深入的文章/电子书/涵盖WebMatrix技术.到目前为止,我正在寻找@MSDN视频教程,但我想深入挖掘,所以寻求深入的技术报道.如果您可以推荐一个,或提供链接,我将不胜感激.Thanx提前.

webmatrix

1
推荐指数
1
解决办法
763
查看次数

无法在WebMatrix(razor)App_Data文件夹中访问我的类

我已经尝试了我在stackoverflow上找到的每个解决方案,但我似乎无法访问我在App_Data文件夹中创建的类.

如果我有这个类(只显示该类的一部分):

public class Encryption
{
    public string Encrypt(string plainText, string Key)
   {
       byte[] key = StringToByteArray(Key);
       string encrypted = ByteArrayToHexString(encryptStringToBytes_AES(plainText, key, null));
       return encrypted;
   }
}
Run Code Online (Sandbox Code Playgroud)

我应该能够在代码块中访问它,如:

@{
    Encryption enc = new Encryption();
    var data = enc.Encrypt("hello", "world");
}
Run Code Online (Sandbox Code Playgroud)

但是我收到一个错误,即无法找到类型或命名空间"加密".

我也尝试用命名空间导入它,但似乎无法将我的应用程序名称显示为命名空间,在asp.net mvc中似乎更简单.

我尝试了所有可以找到的更新配置文件的例子,但无济于事.有什么我需要做的,我在这里失踪了吗?

asp.net class app-data webmatrix razor

1
推荐指数
1
解决办法
1149
查看次数

我应该如何处理表单中的单引号以帮助防止SQL注入,使用WebMatrix razor(C#)

目前我根本不允许使用撇号(以及你可以看到的其他角色),对每个字段重复:

foreach(char c in Comments)
    {
        if(c=='\'' || c=='$' || c=='\"' || c=='&' || c=='%' || c=='@' || c=='-' || c=='<' || c=='>')
        {
            errorMessage = "You have entered at least one invalid character in the \"Comments\" field. Invalid characters are: [\'], [\"], [&], [$], [@], [-], [<], [>], and [%]";
        }
    }
Run Code Online (Sandbox Code Playgroud)

我已经编写了一段时间,我正在变得更好,但真正的问题是,虽然我确信有一种方法可以有效地"剥离"或以其他方式验证用户输入,但我不确定方法是最好的,可能直到安全危机迫在眉睫.

如果必须的话,我会决定永远不会允许单引号进入表格(就像现在一样),但是这可能会加剧任何名字的人... Bill O'Reilly的名字字段等等.

可能还有其他(我不知道该怎么称呼它们,'插件?''在程序之外?')可以为我做这个工作,但这实际上是无用的,因为我不仅不知道如何为了整合它,我不知道如何专门定制它到我的Web界面/数据库.

是否有任何代码可以帮助我从正常的撇号中检测sql注入撇号(通过它周围的字符?)?请记住,我的一些字段最多可容纳500个字符(textareas),最多可容纳1,000个字符.

感谢您的任何想法或帮助!

c# sql sql-injection webmatrix razor

1
推荐指数
1
解决办法
294
查看次数

如何使用webmatrix将图像添加到iTextSharp中的表格单元格中

我已经制作了一个带有单元格的表,并且有兴趣在其中一个单元格中创建一个图像.以下是我的代码:

doc.Open();
PdfPTable table = new PdfPTable(2);
table.TotalWidth = 570f;
table.LockedWidth = true;
table.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right

PdfPCell points = new PdfPCell(new Phrase("and is therefore entitled to 2 points", arialCertify));
points.Colspan = 2;
points.Border = 0;
points.PaddingTop = 40f;
points.HorizontalAlignment = 1;//0=Left, 1=Centre, 2=Right
table.AddCell(points);

 // add a image



doc.Add(table);
Image jpg = Image.GetInstance(imagepath + "/logo.jpg");
doc.Add(jpg);
Run Code Online (Sandbox Code Playgroud)

使用上面的代码,图像显示在我的pdf中,但我希望它在一个单元格中,以便我可以在图像的右侧添加更多单元格.

asp.net itextsharp webmatrix razor

1
推荐指数
1
解决办法
3万
查看次数

我在WebMatrix的单独.cs文件中使用什么using指令用于Server.MapPath?

我试图在WebMatrix Server.MapPath()的单独.cs文件中使用.

我可以使用这个方法 HttpContext.Current.Server.MapPath("~/SomeDirectory/someFile.txt")

但我HttpContext.Current每次都要打字吗?

是不是有任何使用指令来缩短我的输入,Server.MapPath就像在.cshtml文件中编码一样?

我看过这里,但没有一个答案对我有用.可能是因为其中的答案并不针对asp.net-webpages,WebMatrix环境.

http://www.sitepoint.com/forums/showthread.php?167802-Server-MapPath-in-C-class

使用Server.Mappath()

另外,如果有一种备忘单可以帮助我找到C#.net使用指令,考虑到我的环境,让我知道我在哪里可以找到它绝对是一个可以接受的答案.

c# asp.net using-directives webmatrix

1
推荐指数
1
解决办法
4076
查看次数

尝试将数据库发布到没有聚簇索引的Azure时出错

尝试将我的数据库发布到我的Azure站点时,我收到以下错误:

17:13:29: Could not publish the site. Unable to publish the database. For more information, see "http://go.microsoft.com/fwlink/?LinkId=205387"
17:13:29: Error detail:
17:13:29: An error occurred during execution of the database script. The error occurred between the following lines of the script: "332" and "334". The verbose log might have more information about the error. The command started with the following:
17:13:29: "INSERT [dbo].[DBStatus] ([LastIndex], [LastUpdated"
17:13:29:  Tables without a clustered index are not supported in this version of SQL Server. Please …
Run Code Online (Sandbox Code Playgroud)

sql sql-server azure webmatrix

1
推荐指数
1
解决办法
3031
查看次数