Razor会自动的将输出进行Html编码,可以帮助防止跨站点攻击。
如果有人将恶意脚本放进数据库,而Razor没有进行Html编码的话,浏览器就会看到一个<script>标签和可执行的JavaScript。
分类目录归档:.Net
ActionResults action returns
Name | Framework Behavior | Producing Method |
---|---|---|
ContentResult | Returns a string literal | Content |
EmptyResult | No response | |
FileContentResult FilePathResult FileStreamResult |
Return the contents of a file | File |
HttpUnauthorizedResult | Returns an HTTP 403 status | |
JavaScriptResult | Returns a script to execute | JavaScript |
JsonResult | Returns a data in JSON format | Json |
RedirectResult | Redirects the client to a new URL | Redirect |
RedirectToRouteResult | Redirect to another action, or another controller’s action |
RedirectToRoute RedirectToAction |
ViewResult PartialViewResult |
Response is the responsibility of a view engine |
View/PartialView |
C#二叉树
public class TreeNode{ private T data; private TreeNode leftNode; private TreeNode rightNode; public TreeNode(T nodeValue) { data = nodeValue; leftNode = null; rightNode = null; } //数据 public T Data { get { return data; } set { data = value; } } //左子树 public TreeNode LeftNode { get { return leftNode; } set { leftNode = value; } } //右子树 public TreeNode RightNode { get { return rightNode; } set { rightNode = value; } } /// /// 前序遍历:先跟节点然后左子树,右子树 /// /// public void PreOrderTree(TreeNoderoot) { if (root != null) { Console.Write(root.Data); PreOrderTree(root.LeftNode); PreOrderTree(root.RightNode); } } /// /// 中序遍历:左子树,根节点,右子树可以实现顺序输出 /// /// public void InOrderTree(TreeNoderoot) { if (root != null) { InOrderTree(root.LeftNode); Console.Write(root.Data); InOrderTree(root.RightNode); } } /// /// 深度 /// /// ///public int GetTreeDepth(TreeNode tree) { if (tree == null) return 0; int leftDepth = GetTreeDepth(tree.LeftNode); int rightDepth = GetTreeDepth(tree.RightNode); return leftDepth > rightDepth ? (leftDepth + 1) : (rightDepth + 1); } }
C#反转链表
public class ReverseLinkedList { void main() { Nodelist = InitList(); Console.WriteLine(list); list = list.ReverseList(list); Console.WriteLine(list); } public Node InitList() { Node head = new Node (); head.Next = null; head.Data = -1; Node q, p; p = head; for (int i = 1; i <= 10; i++) { q = new Node (); q.Data = i; q.Next = null; p.Next = q; p = q; } return head; } } public class Node { private T data; private Node next; public T Data { get { return data; } set { this.data = value; } } public Node Next { get { return next; } set { next = value; } } public Node ReverseList(Node head) { if (head.Next == null || head.Next.Next == null) { return head; /*链表为空或只有一个元素则直接返回*/ } Node t = null, p = head.Next, q = head.Next.Next; while (q != null) { t = q.Next; q.Next = p; p = q; q = t; } /*此时q指向原始链表最后一个元素,也是逆转后的链表的表头元素*/ head.Next.Next = null; /*设置链表尾*/ head.Next = p; /*调整链表头*/ return head; } public override string ToString() { string result = string.Empty ; Node p = this.Next; while (p != null) { result += string.Format("{0}t", p.Data); p = p.Next; } return result; } }
Html.BeginForm add class attribute
@Html.BeginForm("DoSearch", "Search", FormMethod.Post, new { @class = "myclass"})
Add/remove site map node using MvcSiteMapProvider
add new CustomSiteMapProvider
public class CustomSiteMapProvider : DefaultSiteMapProvider { public void ClearSiteMap() { Clear(); } }
Change web.config file to use the custom sitemapprovider instead of DefaultSiteMapProvider.
When node changes, add
((CustomSiteMapProvider)SiteMap.Provider).ClearSiteMap();
Umbraco:get datatype values
Code:
@{ //var prevalues = umbraco.library.GetPreValues(1235); var prevalues = umbraco.cms.businesslogic.datatype.PreValues.GetPreValues(1235); }@prevalues.ToString()
@if (prevalues.Count > 0) { for (int i=0;i@prevalue.Id:@prevalue.Value } } }
output:
System.Collections.SortedList
81:国内
82:国外
83:资金
84:技术
85:人才
.net mvc display image from file
controller:
public ActionResult Image(string id)
{
var dir = Server.MapPath("/Images");
var path = Path.Combine(dir, id + ".jpg");
return base.File(path, "image/jpeg");
}
view:
<img src="@Url.Action("Image", new { id= Model.Guid })" alt="@Model.Name" width="300" >
IIS .net upload large file congif
IIS 7.x,
?<system.webServer> <security> <requestFiltering> <requestLimits maxAllowedContentLength="2147483648" /> </requestFiltering> </security> </system.webServer>
IIS 6.0
?<system.web> <httpRuntime maxRequestLength="2097151" /> </system.web>
nhibernate cascade delete
<bag name="FileTagRelations" table="FileTagRelation" inverse="true" cascade="delete">
<key column="FileID" foreign-key="FileID" />
<one-to-many class="Entity.FileTagRelationEntity, Entity"/>
</bag>