Invariants of the group of diagonal matrices

Let $D_n$ denote the group of diagonal matrices in $GL_n(\mathbb F_q)$. Then $D_n$ acts on $\mathbb F_q^n$. What are the polynomial invariants of this action ? What are the invariants if we consider $D_n$ as a subgroup of $SL_n$ ?

-
Let $K = \mathbb F_q[X_1 \ldots X_n]$. $D_n$ acts on $K$ by acting on the indeterminates, and you are asking about the polynomials fixed by this action (usually noted $K^{D_n}$)
Since $D_n$ doesn't permute the $X_i$, this means we only need to find the invariant monomials. If $P = X_1^{a_1} \ldots X_n^{a_n}$, and $M$ is the diagonal matrix $(d_1, \ldots ,d_n)$ where $d_i \in \mathbb F_q^*$, then $M . P = (d_1^{a_1} X_1^{a_1}) \ldots (d_n^{a_n} X_n^{a_n}) = P(d_1,\ldots ,d_n) .P$ . Thus, $P$ is invariant by $M$ if and only if $P(d_1,\ldots,d_n) = 1$. Letting $d_1$ be a generator or $\mathbb F_q^*$ and the other $d_i$ be $1$, we get that $a_1$ must be a multiple of $(q-1)$. We do the same for the other indices to get that $P$ is fixed by $D_n$ if and only if each $a_i$ is a multiple of $(q-1)$, thus $K^{D_n} = \mathbb F_q[X_1^{q-1}, \ldots, X_n^{q-1}]$
If $D_n' = D_n \cap SL_n(\mathbb F_q)$ is the subgroup of diagonal matrices with determinant $1$, then the invariant monomials are those satisfying $P(d_1, \ldots d_n) = 1$ for every $(d_1, \ldots d_n) \in (\mathbb F_q^*)^n$ satisfying $d_1 d_2 \ldots d_n = 1$, thus $K^{D_n'}$ is simply $K^{D_n}[X_1X_2 \ldots X_n] = \mathbb F_q[X_1^{q-1}, \ldots , X_n^{q-1},X_1X_2\ldots X_n]$.
And we can check that $K^{D_n'}$ is an extension of $K^{D_n}$ of degree $(q-1)$, which is expected since $D'_n$ is a subgroup of $D_n$ of index $(q-1)$.